package com.easou.ps.utils;

import org.apache.log4j.Logger;

public class MatchPropUtil {
	static Logger LOG = Logger.getLogger("common");
	public static boolean matchAnchor(int matchProp) {
		return (matchProp & 0x01) > 0;
	}
	
	public static boolean matchTitle(int matchProp) {
		return (matchProp & 0x02) > 0;
	}
	
	public static boolean matchContent(int matchProp) {
		return (matchProp & 0x04) > 0;
	}
	
	public static boolean matchLink(int matchProp) {
		return (matchProp & 0x08) > 0;
	}
	
	public static boolean matchOffsetLimit(int matchProp) {
		return (matchProp & 0x10) > 0;
	}
	
	public static boolean matchDirect(int matchProp) {
		return (matchProp & 0x20) > 0;
	}

	public static boolean matchSiteRank(int matchProp) {
		return (matchProp & 0x40) > 0;
	}

	public static boolean matchSiteType(int matchProp) {
		return (matchProp & 0x80) > 0;
	}

	public static boolean matchPageType(int matchProp) {
		return (matchProp & 0x100) > 0;
	}

	public static boolean matchTitleCover(int matchProp) {
		return (matchProp & 0x200) > 0;
	}
	
	public static String getMatchInfo(int matchProp) {
		StringBuilder info = new StringBuilder("[");
		if (matchAnchor(matchProp)) {
			append(info, "anchor");
		}
		if (matchTitle(matchProp)) {
			append(info, "title");
		}
		if (matchContent(matchProp)) {
			append(info, "content");
		}
		if (matchLink(matchProp)) {
			append(info, "link");
		}
		if (matchOffsetLimit(matchProp)) {
			append(info, "offsetlimit");
		}
		if (matchDirect(matchProp)) {
			append(info, "direct");
		}
		if (matchSiteRank(matchProp)) {
			append(info, "siterank");
		}
		if (matchSiteType(matchProp)) {
			append(info, "sitetype");
		}
		if (matchPageType(matchProp)) {
			append(info, "pagetype");
		}
		if (matchTitleCover(matchProp)) {
			append(info, "titlecover");
		}
		info.append("]");
//		LOG.info("----------------match" + info.toString() + "-----------" + matchDirect(matchProp));
		return info.toString();
	}
	
	private static void append(StringBuilder info, String value){
		info.append(value + ",");
	}
}
